package com.xk._01基础篇._09集合Set;

import com.xk._01基础篇._09集合Set.file.FileInfo;
import com.xk._01基础篇._09集合Set.file.Files;
import com.xk._01基础篇._09集合Set.set.Set;
import com.xk._01基础篇._09集合Set.set.TreeSet;
import com.xk.tools.Times;

/**
 * @description:
 * @author: xu
 * @date: 2022/9/26 11:04
 */
public class Main {

    public static void main(String[] args) {
        test02();
    }

    private static void test02() {
        FileInfo fileInfo = Files.read("X:\\newJava\\JDK8\\src", new String[]{"java"});
        System.out.println("文件数量：" + fileInfo.getFiles());
        System.out.println("代码行数：" + fileInfo.getLines());
        String[] words = fileInfo.words();
        System.out.println("单词数量：" + words.length);

        /*Times.test("test ListSet", new Times.Task() {
            @Override
            public void execute() {
                testSet(new ListSet<>(), words);
            }
        });*/
        Times.test("test TreeSet", new Times.Task() {
            @Override
            public void execute() {
                testSet(new TreeSet<>(), words);
            }
        });
    }

    private static void testSet(Set<String> set, String[] words) {
        for (int i = 0; i < words.length; i++) {
            set.add(words[i]);
        }
        for (int i = 0; i < words.length; i++) {
            set.contains(words[i]);
        }
        for (int i = 0; i < words.length; i++) {
            set.remove(words[i]);
        }
    }




    private static void test01(){
        Set<Integer> treeSet = new TreeSet<>();
        treeSet.add(12);
        treeSet.add(10);
        treeSet.add(7);
        treeSet.add(11);
        treeSet.add(10);
        treeSet.add(11);
        treeSet.add(9);

        treeSet.traversal(new Set.Visitor<Integer>() {
            @Override
            public boolean visit(Integer element) {
                System.out.println(element);
                return false;
            }
        });
    }
}
